package dhm.com.dhmshop.adapter.order;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.GetAllOrder;
import dhm.com.dhmshop.entity.Myorder;
import dhm.com.dhmshop.framework.module.commodity.activity.CommodityDetailsActivity;
import dhm.com.dhmshop.framework.module.commodity.entity.OneGoodsEntity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class ChildOrderAdapter extends RecyclerView.Adapter<ChildOrderAdapter.ViewHolder> {

    private List<GetAllOrder.DataBean.ListBean> shopList;
    private Context context;


    public ChildOrderAdapter(Context context) {
        this.shopList = new ArrayList<>();
        this.context = context;
    }


    public void setImageList(List<GetAllOrder.DataBean.ListBean> paramList) {
        this.shopList = paramList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_childorder, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.image.setImageURI(Constant.PATH+"/"+shopList.get(i).getGoodsImg());
        viewHolder.name.setText(shopList.get(i).getGoodsName());
        if (!shopList.get(i).getGoodsSpecNames().equals("")){
            viewHolder.param.setText(shopList.get(i).getGoodsSpecNames());
        }else {
            viewHolder.param.setVisibility(View.GONE);
        }
        viewHolder.price.setText("￥"+shopList.get(i).getGoodsPrice());
        viewHolder.num.setText("x"+shopList.get(i).getGoodsNum());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, CommodityDetailsActivity.class);
                intent.putExtra("gid",Integer.parseInt(shopList.get(i).getGoodsId()));
//                intent.putExtra("shop_id",shopList.get(i).());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView image;
        public TextView name;
        public TextView price;
        public TextView num;
        public TextView param;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            image=itemView.findViewById(R.id.image);
            name=itemView.findViewById(R.id.name);
            price=itemView.findViewById(R.id.price);
            param=itemView.findViewById(R.id.param);
            num=itemView.findViewById(R.id.num);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion, int childposttion);
    }



}

